package com.atguigu.auth.controller;


import com.atguigu.auth.entity.Environment;
import com.atguigu.auth.entity.Environment;
import com.atguigu.auth.service.EnvironmentService;
import com.atguigu.auth.service.EnvironmentService;
import com.atguigu.common.result.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 环境监控表 前端控制器
 * </p>
 *
 * @author universe
 * @since 2024-03-17
 */
@Api(tags = "环境管理接口")
@RestController
@RequestMapping("/auth/environment")
public class EnvironmentController {
    @Autowired
    private EnvironmentService service;
    //条件分页查询
    @ApiOperation("条件分页查询")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page,
                        @PathVariable Long limit,
                        Environment environment) {
        //创建page对象
        Page<Environment> pageParam = new Page<>(page,limit);

        //封装条件，判断条件值不为空
        LambdaQueryWrapper<Environment> wrapper = new LambdaQueryWrapper<>();
//        //获取条件值
//        String Environmentname = EnvironmentQueryVo.getKeyword();
//        String createTimeBegin = EnvironmentQueryVo.getCreateTimeBegin();
//        String createTimeEnd = EnvironmentQueryVo.getCreateTimeEnd();
//        //判断条件值不为空
//        //like 模糊查询
//        if(!StringUtils.isEmpty(Environmentname)) {
//            wrapper.like(Environment::getEnvironmentname,Environmentname);
//        }
//        //ge 大于等于
//        if(!StringUtils.isEmpty(createTimeBegin)) {
//            wrapper.ge(Environment::getCreateTime,createTimeBegin);
//        }
//        //le 小于等于
//        if(!StringUtils.isEmpty(createTimeEnd)) {
//            wrapper.le(Environment::getCreateTime,createTimeEnd);
//        }

        //调用mp的方法实现条件分页查询
        IPage<Environment> pageModel = service.page(pageParam, wrapper);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "获取")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id) {
        Environment environment = service.getById(id);
        return Result.ok(environment);
    }

    @ApiOperation(value = "保存")
    @PostMapping("save")
    public Result save(@RequestBody Environment environment) {

        service.save(environment);
        return Result.ok();
    }

    @ApiOperation(value = "更新")
    @PutMapping("update")
    public Result updateById(@RequestBody Environment environment) {
        service.updateById(environment);
        return Result.ok();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        service.removeById(id);
        return Result.ok();
    }
}

